package org.example.Command;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.Exceptions.WrongArgsException;
import org.example.Utils.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;

@NoArgsConstructor
@Data
public class SendMessage extends Command {

    File file;

    public SendMessage(String commandStr, HashMap<String, String> args) {
        super(commandStr, args, SEND_COMMAND);
        file = new File(args.get("-f"));
    }

    @Override
    public void check() throws Exception {
        String file = args.get("-f");
        Path path = Paths.get(file);
        if (!Files.exists(path)) {
            throw new FileNotFoundException();
        }

        if (args.get("-d") != null) {
            String times = args.get("-d");
            if (Integer.parseInt(times) < 0) throw new WrongArgsException("-d", "不能正确识别的指令");
        }

        if (args.get("-t") != null) {
            List<String> time = StringUtils.getTimeUnit(args.get("-t"));
            String timeUnit = time.get(1);
            if ("SECONDS".equalsIgnoreCase(timeUnit) || "sec".equalsIgnoreCase(timeUnit) || "s".equalsIgnoreCase(timeUnit)
                    || "DAYS".equalsIgnoreCase(timeUnit) || "d".equalsIgnoreCase(timeUnit)
                    || "HOURS".equalsIgnoreCase(timeUnit) || "h".equalsIgnoreCase(timeUnit)
                    || "MINUTES".equalsIgnoreCase(timeUnit) || "min".equalsIgnoreCase(timeUnit) || "m".equalsIgnoreCase(timeUnit)) {

            } else throw new WrongArgsException("-t", "未知的时间参数");
        }
    }
}
